#ifndef INFINITY_WORLD_AREA_INL
#	define INFINITY_WORLD_AREA_INL

namespace infinity {

inline WorldArea::WorldArea()
:	m_id(0, 0, 0)
{
}

inline WorldArea::~WorldArea()
{
	m_sectors.clear();
}

/*static*/ inline Vector3i WorldArea::getAreaIdFromSector(const Vector3i& sectorId)
{
	Vector3i areaId;

	areaId.x = sectorId.x / SideSectors - (sectorId.x < 0 ? 1 : 0);
	areaId.y = sectorId.y / SideSectors - (sectorId.y < 0 ? 1 : 0);
	areaId.z = sectorId.z / SideSectors - (sectorId.z < 0 ? 1 : 0);

	return areaId;
}

/*static*/ inline Vector3i WorldArea::getAreaIdFromCell(const Vector3i& cellId)
{
	Vector3i areaId;

	areaId.x = cellId.x / SideCells - (cellId.x < 0 ? 1 : 0);
	areaId.y = cellId.y / SideCells - (cellId.y < 0 ? 1 : 0);
	areaId.z = cellId.z / SideCells - (cellId.z < 0 ? 1 : 0);

	return areaId;
}

inline void WorldArea::addSector(WorldSector* sector)
{
	dwAssert(sector != NULL, "Invalid parameter: sector is NULL");
	dwAssert(getAreaIdFromSector(sector->getId()) == m_id, "Invalid parameter: sector doesn't belong to this area");
	dwAssert(std::find(m_sectors.begin(), m_sectors.end(), sector) == m_sectors.end(), "Invalid parameter: sector is already registered in this area");

	m_sectors.push_back(sector);
}

inline void WorldArea::setId(const Vector3i& id)
{
	dwAssert(m_sectors.empty(), "Invalid call to setId, area is not empty");

	m_id = id;
}

inline const Vector3i& WorldArea::getId() const
{
	return m_id;
}

} // namespace infinity

#endif // !INFINITY_WORLD_AREA_INL
